package momo.app.util;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class FileOutput
{
	private static FileOutput out;
	private Map<String, FileCreator> creators;
	
	private FileOutput()
	{
		creators = Collections.synchronizedMap(new HashMap<String, FileCreator>());
	}
	
	static public FileOutput getInstance()
	{
		if ( out == null )
			out = new FileOutput();
		return out;
	}
	
	public FileCreator getFileCreator(String filename)
	{
		FileCreator creator = creators.get(filename);
		if ( creator == null )
		{
			creator = new FileCreator(filename);
			creators.put(filename, creator);
		}
		return creator;
	}
	
	public FileCreator getFileCreator(String filename, String directoryUsed)
	{
		FileCreator creator = creators.get(filename);
		if ( creator == null )
		{
			creator = new FileCreator(filename, directoryUsed);
			creators.put(filename, creator);
		}
		return creator;
	}
	
	public void logToFile(String filename, String contents)
	{
		FileCreator creator = getFileCreator(filename);
		creator.logToFile(contents);
	}
	
	public void logToFile(String filename, String directoryUsed, String contents)
	{
		FileCreator creator = getFileCreator(filename, directoryUsed);
		creator.logToFile(contents);
	}
	
}//end of class FileOutput
